/**
 * Copyright (C)  Gadglet .
 *
 * This file is part of Gadglet
 *
 * Gadglet is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gadglet is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Gadglet. If not, see <http://www.gnu.org/licenses/>.
 */

package com.gadglet.data;

import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.users.User;

/**
 * Persistence class for Domain users registration
 *
 */
@PersistenceCapable
public class RegistrationToken {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String tokenId;
	
	@Persistent
	private Date creation;
	
	@Persistent
	private String openSocialViewerId;
	
	@Persistent
	private String consumerKey;
	
	@Persistent
	private String oauthUserId;

	@Persistent
	private String authDomain;
	
	@Persistent
	private String email;
	
	
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getAuthDomain() {
		return authDomain;
	}

	void setAuthDomain(String authDomain) {
		this.authDomain = authDomain;
	}

	void setOpenSocialViewerId(String openSocialViewrId) {
		this.openSocialViewerId = openSocialViewrId;
	}

	void setConsumerKey(String consumerKey) {
		this.consumerKey = consumerKey;
	}

	void setOauthUserId(String oauthId) {
		this.oauthUserId = oauthId;
	}
	
	public String getOauthUserId() {
		return oauthUserId;
	}

	public String getTokenID() {
		return tokenId;
	}

	Date getCreation() {
		return creation;
	}

	public String getOpenSocialViewerId() {
		return openSocialViewerId;
	}

	public String getConsumerKey() {
		return consumerKey;
	}
	
	

	RegistrationToken(String openSocialViewrId,
			String consumer_key) {
		this.creation = new java.util.Date();
		this.openSocialViewerId = openSocialViewrId;
		this.consumerKey = consumer_key;
	}
	
	RegistrationToken(User user) {
	
		this.creation = new java.util.Date();
		this.oauthUserId = user.getUserId();
		this.authDomain = user.getAuthDomain();
		this.email = user.getEmail();
	}
	
	public boolean isTokenReady(){
	if(isOauthReady() && isOpenSocialReady())		
		return true;
	else
		return false;
	}
	
	public boolean isOauthReady(){
		if(oauthUserId == null || authDomain == null)
			return false;
		else
			return true;
		
	}
	
	
	public boolean isOpenSocialReady(){
		if(openSocialViewerId == null || consumerKey == null)
			return false;
		else
			return true;
		
	}
	
	

}
